

public class Map {
	private final int width;
	private final int height;
	public Tile[][] tiles;

	public Map(String[] s) {
		
		width = s[0].length()-1;
		height = s.length-1;
		tiles = new Tile[width][height];

		for (int i = 0; i < height; i++) {
			for (int j = 0; j < width; j++) {
				tiles[i][j] = new Tile(i, j, s[i].charAt(j));
			}
		}
	}

	
	//=========== GETTERS ==============
	public String getTileLabel(int x, int y) {return tiles[y][x].toString();}
	public int width() {return this.width;}
	public int height() {return this.height;}
	
	
	public String toString() {
		String s = "";
		for (int i = 1; i < width; i++) {
			for (int j = 1; j < height; j++) {
				s += tiles[i][j].toString();
			}
			s += "\n";
		}
		return s;
	}
	
	// =============== SETTERS ==================
	public void setLabel(int x, int y, char _label){tiles[x][y].setLabel(_label);}
	public boolean addTileable(int x, int y, Tileable tile){return tiles[x][y].addTileable(tile);}
	public boolean removeTileable(int x, int y, Tileable tile){return tiles[x][y].removeTileable(tile);}
	
	// =============== DO STUFF =================
	public void visible(int x, int y, int range){
		for (int i=Math.max(1, x-range); i<= Math.min(x+range, width()); i++)
			for(int j=Math.max(1, y-range); j<=Math.min(y+range, height());j++)
				tiles[i][j].visible();
	}
	
	public void invisible(int x, int y, int range){
		for (int i=Math.max(1, x-range); i<= Math.min(x+range, width()); i++)
			for(int j=Math.max(1, y-range); j<=Math.min(y+range, height());j++)
				tiles[i][j].invisible();
	}
	
	public void terrain(int x, int y){tiles[x][y].terrain();}
	
	public void update(){
		for(int i = 0; i<width(); i++)
			for(int j = 0; j<height(); j++)
				tiles[i][j].setLabel('-');
	}
	
	public boolean assign(int x, int y){return tiles[x][y].assign();}
	
	public boolean die(int x, int y, Tileable tile){return tiles[x][y].removeTileable(tile);}
}
